home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / recode.lha / recode-3.2.4 / steps.h < prev    next >
C/C++ Source or Header  |  1992-09-25  |  7KB  |  174 lines

  1. /* Conversion of files between different charsets and usages.
  2.    Copyright (C) 1990 Free Software Foundation, Inc.
  3.    Francois Pinard <pinard@iro.umontreal.ca>, 1988.
  4.  
  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 2, or (at your option)
  8.    any later version.
  9.  
  10.    This program is distributed in the hope that it will be useful, but
  11.    WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public License
  16.    along with this program; if not, write to the Free Software
  17.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. /* The following declarations are included by the main program only.
  21.  
  22.    The purpose of this separate file is to keep the main program pure of any
  23.    particular character set, while providing the linking mechanism between the
  24.    general algorithm with the currently available conversion routines.
  25.  
  26.    Adding a new character set or usage requires a single file for the
  27.    conversion tables and routines, and modifying this inclusion file.
  28. */
  29.  
  30. typedef enum            /* Codes for available charsets */
  31.   {
  32.     CODE_APPLEMAC,        /* ASCII 8 bits for Apple's Macintosh */
  33.     CODE_ASCII,            /* ASCII 7 bits, <BS> to overstrike */
  34.     CODE_BANGBANG,        /* ASCII "bang bang", escapes are ! and !! */
  35.     CODE_CCCASCII,        /* ASCII 8 bits as seen by Perkin Elmer */
  36.     CODE_CDCASCII,        /* ASCII 8 bits as seen by Control Data */
  37.     CODE_CDCNOS,        /* ASCII 6/12 from NOS, escapes are ^ and @ */
  38.     CODE_EBCDIC,        /* EBCDIC */
  39.     CODE_FLAT,            /* ASCII without diacritics nor underline */
  40.     CODE_IBMPC,            /* ASCII 8 bits for IBM's PC */
  41.     CODE_ICONQNX,        /* ASCII with diacritics for Unisys'ICON */
  42.     CODE_LATEX,            /* ASCII with LaTeX codes */
  43.     CODE_LATIN1,        /* ASCII extended by Latin Alphabet 1 */
  44.     CODE_TEXTE            /* ASCII with easy French conventions */
  45.   }
  46. TYPE_code;
  47.  
  48. #ifdef ENUM_INT_BUG
  49. #define TYPE_code int
  50. #endif
  51.  
  52. /* The following array provides strings to represent available codes, and is
  53.    parallel to TYPE_code declaration.  Each entry contains two strings:
  54.    first a short form containing four letters, the same four letters used to
  55.    name the conversion routines of this package; then a long form giving a
  56.    more explicit strings.  */
  57.  
  58. struct keyword_struct
  59.   {
  60.     const char *s;
  61.     const char *l;
  62.   }
  63. code_keywords[] =
  64.   {
  65.     { "maci", "applemac" },
  66.     { "asci", "ascii" },
  67.     { "bang", "bangbang" },
  68.     { "ccca", "cccascii" },
  69.     { "cdca", "cdcascii" },
  70.     { "cdcn", "cdcnos" },
  71.     { "ebcd", "ebcdic" },
  72.     { "flat", "flat" },
  73.     { "ibmp", "ibmpc" },
  74.     { "icon", "iconqnx" },
  75.     { "ltex", "latex" },
  76.     { "lat1", "latin1" },
  77.     { "txte", "texte" },
  78.   };
  79.  
  80. #define NUMBER_OF_KEYWORDS \
  81.   (sizeof (code_keywords) / sizeof (struct keyword_struct))
  82.  
  83. /* Description of all available conversion routines. */
  84.  
  85. #ifndef __STDC__
  86. #define PARAMLIST ()
  87. #else
  88. #define PARAMLIST (FILE *, FILE *)
  89. #endif
  90.  
  91. extern void applemac_ibmpc    PARAMLIST;
  92. extern void ascii_cdcnos    PARAMLIST;
  93. extern void ascii_flat        PARAMLIST;
  94. extern void ascii_latex        PARAMLIST;
  95. extern void ascii_texte        PARAMLIST;
  96. extern void bangbang_latin1    PARAMLIST;
  97. extern void cccascii_ebcdic    PARAMLIST;
  98. extern void ascii8_ascii7    PARAMLIST;
  99. extern void cdcascii_ebcdic    PARAMLIST;
  100. extern void cdcnos_ascii    PARAMLIST;
  101. extern void ebcdic_cccascii    PARAMLIST;
  102. extern void ebcdic_cdcascii    PARAMLIST;
  103. extern void ibmpc_applemac    PARAMLIST;
  104. extern void ibmpc_iconqnx    PARAMLIST;
  105. extern void ibmpc_latin1    PARAMLIST;
  106. extern void iconqnx_ibmpc    PARAMLIST;
  107. extern void latex_ascii        PARAMLIST;
  108. extern void latex_latin1    PARAMLIST;
  109. extern void latin1_bangbang    PARAMLIST;
  110. extern void latin1_ibmpc    PARAMLIST;
  111. extern void latin1_latex    PARAMLIST;
  112. extern void latin1_texte    PARAMLIST;
  113. extern void texte_ascii        PARAMLIST;
  114. extern void texte_latin1    PARAMLIST;
  115.  
  116. #undef PARAMLIST
  117.  
  118. /* Constants for conversion costs. */
  119.  
  120. #define NOWAY    10000        /* No way for this conversion */
  121.  
  122. #define STEP    100        /* Nominal value for each step */
  123. #define ALREADY    0        /* The code injects, no conversion */
  124.  
  125. #define LOOSE    +10        /* Some characters are thrown away */
  126. #define EXACT    -10        /* The conversion would be reversible */
  127.  
  128. #define SLOW    +1        /* Multiple characters to one */
  129. #define FAST    -1        /* One character to one */
  130.  
  131. typedef struct 
  132.   {
  133. #ifndef __STDC__
  134.     void (*routine) ();        /* Address of conversion routine */
  135. #else
  136.     void (*routine) (FILE *, FILE *); /* Address of conversion routine */
  137. #endif
  138.     TYPE_code code_before;    /* Code of charset before conversion */
  139.     TYPE_code code_after;    /* Code of charset after conversion */
  140.     int conversion_cost;    /* Bonuses and penalties */
  141.   }
  142. TYPE_of_step;
  143.  
  144. TYPE_of_step single_steps[] =    /* Table of elementary conversions */
  145.   {
  146.     { applemac_ibmpc,    CODE_APPLEMAC,    CODE_IBMPC,    STEP LOOSE FAST },
  147.     { NULL,        CODE_ASCII,    CODE_CDCASCII,    ALREADY         },
  148.     { ascii_cdcnos,    CODE_ASCII,    CODE_CDCNOS,    STEP EXACT      },
  149.     { ascii_flat,    CODE_ASCII,    CODE_FLAT,    STEP LOOSE      },
  150.     { ascii_latex,    CODE_ASCII,    CODE_LATEX,    STEP LOOSE SLOW },
  151.     { ascii_texte,    CODE_ASCII,    CODE_TEXTE,    STEP       SLOW },
  152.     { bangbang_latin1,    CODE_BANGBANG,    CODE_LATIN1,    STEP EXACT      },
  153.     { cccascii_ebcdic,    CODE_CCCASCII,    CODE_EBCDIC,    STEP EXACT FAST },
  154.     { ascii8_ascii7,    CODE_CDCASCII,    CODE_ASCII,    STEP LOOSE FAST },
  155.     { cdcascii_ebcdic,    CODE_CDCASCII,    CODE_EBCDIC,    STEP EXACT FAST },
  156.     { cdcnos_ascii,    CODE_CDCNOS,    CODE_ASCII,    STEP EXACT      },
  157.     { ebcdic_cccascii,    CODE_EBCDIC,    CODE_CCCASCII,    STEP EXACT FAST },
  158.     { ebcdic_cdcascii,    CODE_EBCDIC,    CODE_CDCASCII,    STEP EXACT FAST },
  159.     { ibmpc_applemac,    CODE_IBMPC,    CODE_APPLEMAC,    STEP LOOSE FAST },
  160.     { ibmpc_iconqnx,    CODE_IBMPC,    CODE_ICONQNX,    STEP            },
  161.     { ibmpc_latin1,    CODE_IBMPC,    CODE_LATIN1,    STEP LOOSE      },
  162.     { iconqnx_ibmpc,    CODE_ICONQNX,    CODE_IBMPC,    STEP LOOSE SLOW },
  163.     { latex_ascii,    CODE_LATEX,    CODE_ASCII,    STEP LOOSE SLOW },
  164.     { latex_latin1,    CODE_LATEX,    CODE_LATIN1,    STEP LOOSE SLOW },
  165.     { latin1_bangbang,    CODE_LATIN1,    CODE_BANGBANG,    STEP LOOSE FAST },
  166.     { latin1_ibmpc,    CODE_LATIN1,    CODE_IBMPC,    STEP LOOSE      },
  167.     { latin1_latex,    CODE_LATIN1,    CODE_LATEX,    STEP LOOSE      },
  168.     { latin1_texte,    CODE_LATIN1,    CODE_TEXTE,    STEP LOOSE    },
  169.     { texte_ascii,    CODE_TEXTE,    CODE_ASCII,    STEP       SLOW },
  170.     { texte_latin1,    CODE_TEXTE,    CODE_LATIN1,    STEP LOOSE SLOW }
  171.   };
  172.  
  173. #define NUMBER_OF_SINGLE_STEPS (sizeof (single_steps) / sizeof (TYPE_of_step))
  174.